package View;

import Controller.SimulationHandler;
import UCM.UCCloseIntersectionOptions;
import UCM.UCSetIntersection;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * This class is a modified JFrame
 *
 * @author Matthew
 *         Date: Oct 5, 2010
 *         Time: 10:02:28 PM
 */
public class IntersectionOptions extends JFrame {

    private JLabel HNUMLANESLABEL;
    private JLabel HPROBLABEL;
    private JLabel VNUMLANESLABEL;
    private JLabel VPROBLABEL;
    private JLabel horMinMaxLabel;
    private JLabel vertMinMaxLabel;
    private JLabel HPROBMINMAXLABEL;
    private JLabel VPROBMINMAXLABEL;
    private JButton cancelBttn;
    private JButton setBttn;
    private JTextField numHorLanesText;
    private JTextField numVertLanesText;
    private JTextField horProbText;
    private JTextField vertProbText;

    private SimulationHandler sh;

    public JTextField getHorLanesText() {
        return numHorLanesText;
    }

    public JTextField getVertLanesText() {
        return numVertLanesText;
    }

    public JTextField getHorProbText() {
        return horProbText;
    }

    public JTextField getVertProbText() {
        return vertProbText;
    }

    /**
     * Frame Constructor
     *
     * @param shs = SimulationHandler
     */
    public IntersectionOptions(SimulationHandler shs) {
        //Set object references
        this.sh = shs;
        //Set labels
        HNUMLANESLABEL = new JLabel("Number Of Horizontal Lanes: ");
        HPROBLABEL = new JLabel("Probability of car entering H-Street: ");
        VNUMLANESLABEL = new JLabel("Number Of Vertical Lanes: ");
        VPROBLABEL = new JLabel("Probability of car entering V-Street: ");
        horMinMaxLabel = new JLabel("(Min 1 Max 3)");
        vertMinMaxLabel = new JLabel("(Min 1 Max 4)");
        HPROBMINMAXLABEL = new JLabel("(Between 0 & 1)");
        VPROBMINMAXLABEL = new JLabel("(Between 0 & 1)");
        //Set buttons
        cancelBttn = new JButton("Close");
        setBttn = new JButton("Set");
        numHorLanesText = new JTextField("2");
        numVertLanesText = new JTextField("2");
        horProbText = new JTextField("0.5");
        vertProbText = new JTextField("0.5");
        //Create panels
        JPanel inputs = new JPanel();
        JPanel buttons = new JPanel();
        JPanel main = new JPanel();

        //Inputs Panel
        inputs.setLayout(new GridLayout(0, 3));
        inputs.add(HNUMLANESLABEL);
        inputs.add(numHorLanesText);
        inputs.add(horMinMaxLabel);
        inputs.add(HPROBLABEL);
        inputs.add(horProbText);
        inputs.add(HPROBMINMAXLABEL);
        inputs.add(VNUMLANESLABEL);
        inputs.add(numVertLanesText);
        inputs.add(vertMinMaxLabel);
        inputs.add(VPROBLABEL);
        inputs.add(vertProbText);
        inputs.add(VPROBMINMAXLABEL);

        //Buttons Panel
        buttons.add(cancelBttn);
        buttons.add(setBttn);

        //Main Panel
        main.setLayout(new BorderLayout());
        main.add(inputs, BorderLayout.CENTER);
        main.add(buttons, BorderLayout.SOUTH);

        //Frame
        add(main);
        setSize(700, 200);
        setTitle("Intersection Settings");

        //Button action listeners
        cancelBttn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new UCCloseIntersectionOptions(sh).run();
            }
        });
        setBttn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new UCSetIntersection(sh).run();

            }
        });
        pack();

    }
    //Test Frame

    public static void main(String[] args) {
        IntersectionOptions IO = new IntersectionOptions(new SimulationHandler());
        IO.setVisible(true);

    }
}
